package com.product.service.module.sys.service;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.product.CopyUtils;
import com.product.module.sys.dto.SystemUserDto;
import com.product.module.sys.service.SystemUserService;
import com.product.service.module.sys.dao.SystemUserDao;
import com.product.service.module.sys.entity.SystemUserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 *
 * @author bobo
 * @date 2020-07-31 10:29:03
 */
@Service
public class SystemUserServiceImpl implements SystemUserService{

    private static final Logger LOGGER = LoggerFactory.getLogger(SystemUserService.class);

    @Autowired
    private SystemUserDao systemUserDao;


    @Override
    public List<SystemUserDto> queryList(Map<String,Object> params){
        List<SystemUserEntity> list = systemUserDao.queryList(params);
        return CopyUtils.copyList(list,SystemUserDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> params){
        return systemUserDao.queryTotal(params);
    }

    @Override
    public Long save(SystemUserDto dto){
        SystemUserEntity entity = CopyUtils.copyObj(dto,SystemUserEntity.class);
        //hutool 的 雪花算法
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        entity.setId(snowflake.nextId());
        systemUserDao.insert(entity);
        return entity.getId();
    }

    @Override
    public void updateById(SystemUserDto dto){
        SystemUserEntity entity = CopyUtils.copyObj(dto,SystemUserEntity.class);
        systemUserDao.updateById(entity);
    }

    @Override
    public SystemUserDto selectById(Serializable id){
        SystemUserEntity entity = systemUserDao.selectById(id);
        return CopyUtils.copyObj(entity,SystemUserDto.class);
    }

    @Override
    public void deleteById(Serializable id){
        systemUserDao.deleteById(id);
    }

    @Override
    @Transactional
    public void deleteBatch(Serializable[] ids){
        for (Serializable id : ids) {
            deleteById(id);
        }
    }
}
